<template>
  <div class="upbox">
    <div class="inputbox">
       <el-input v-model="phone"  placeholder="请填写手机号"></el-input>
    <el-input v-model="password" placeholder="请输入新密码"> </el-input>
    </div>
    <el-upload
    class="upload-demo"
    action="http://182.92.156.134:8080/upload"
    :limit="3"
    :on-success="success"
  >
    <el-button size="small" type="primary">点击上传</el-button>
    <div slot="tip" class="el-upload__tip">
      只能上传jpg/png文件，且不超过500kb
    </div>
  </el-upload>
    <el-button type="danger" @click="changeUser">确认修改</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      img:'',
      phone:'',
      password:''
    };
  },
  methods: {
    success(res){
      this.img=res.url
      console.log(res);
    },
    changeUser(){
      this.$store.dispatch('changeUser',{phone:this.phone,password:this.password,img:this.img,id:this.$store.state.user.userid}).then(res=>{
        if(res.status==200){
          this.$message({
          message: '修改成功',
          type: 'success'
        });
        this.$router.go(0)
        }
      })
    }
  },
};
</script>

<style scoped>
.inputbox{
  width: 300px;
  height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}
.upbox{
  padding: 30px;
}
</style>
